package Sequence;

public class Test0213 {
}

class Solution0213_1 {
    public int rob(int[] nums) {
        int length = nums.length;
        if (length == 1) return nums[0];

        int pre1 = 0,pre2 = 0,now1=0,now2=0;

        for (int i = 0; i < length-1; i++) {
            now1 = Math.max(pre1,pre2+nums[i]);
            pre2 = pre1;
            pre1 = now1;
        }

        pre1 = 0;
        pre2 = 0;
        for (int i = 1; i < length; i++) {
            now2 = Math.max(pre2,pre1+nums[i]);
            pre1 = pre2;
            pre2 = now2;
        }
        return Math.max(now1,now2);
    }
}
